package here;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        Repo repo = new Repo(sc.nextLine());
        Thread t1 = new Thread(new Worker1(repo));
        Thread t2 = new Thread(new Worker2(repo));
        t1.start();
        Thread.yield();
        t2.start();
        sc.close();
    }
}


import java.util.Scanner;
class Repo{
	String[] string;
	static boolean gender1 = true;
	static boolean gender2 = true;
	public Repo(String items) {
		string = items.split(" ");
	}
	int getSize(){
		int size = 0;
		for (int i = 0; i < this.string.length; i++) {
			if (string[i]!= null) size ++;
		}
		return size;
	}
	 public synchronized String deleteTask(){
		String str = string[0];
		for (int i = 0; i < string.length-1; i++) {
			string[i] = string[i+1];
		}
		string[string.length - 1] = null;
		return str;
	}
}
class Worker1 implements Runnable{
	private Repo repo;
	public Worker1(Repo repo) {
		// TODO Auto-generated constructor stub
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize()!=0) {
			if (repo.gender1 == true){
				System.out.println(Thread.currentThread().getName()+" finish "+repo.deleteTask());
			}
		}
		repo.gender1 = false;
		repo.gender2 = true;
	}	
}
class Worker2 implements Runnable{

	private Repo repo;
	public Worker2(Repo repo) {
		// TODO Auto-generated constructor stub
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize()!=0) {
			if (repo.gender2 == true){
				System.out.println(Thread.currentThread().getName()+" finish "+repo.deleteTask());
			}
		}
		Repo.gender1 = true;
		Repo.gender2 = false;
		
	}
}